//
//  File.swift
//  casdon_swiftUI
//
//  Created by ww on 2025/5/17.
//

import SwiftUI

struct EnvironmentEntry: View {
    @Binding var showSheet: Bool
    @State private var tapCount = 0
    @State private var lastTapTime: Date = .distantPast

    var body: some View {
        Color.clear
            .frame(width: 44, height: 44)
            .contentShape(Rectangle())
            .onTapGesture {
                let now = Date()
                if now.timeIntervalSince(lastTapTime) < 1 {
                    tapCount += 1
                } else {
                    tapCount = 1
                }
                lastTapTime = now

                if tapCount >= 5 {
                    tapCount = 0
                    showSheet = true
                }
            }
    }
}
import SwiftUI

struct EnvironmentSelectionSheet: View {
    @Environment(\.dismiss) private var dismiss

    var body: some View {
        NavigationView {
            List {
                Text("修改环境前先退出应用，然后再修改才能生效")
                    .foregroundColor(.red)
                    .font(.system(size: 14))
                    
                Button(action: {
                    EnvironmentConfig.shared.currentType = .dev
                    dismiss()
                }) {
                    HStack {
                        Text("开发环境")
                        Spacer()
                        if EnvironmentConfig.shared.currentType == .dev  {
                            Image(systemName: "checkmark")
                                .foregroundColor(.blue)
                        }
                    }
                }

                Button(action: {
                    
                    EnvironmentConfig.shared.currentType = .uat
                    dismiss()
                }) {
                    HStack {
                        Text("测试环境")
                        Spacer()
                        if EnvironmentConfig.shared.currentType == .uat  {
                            Image(systemName: "checkmark")
                                .foregroundColor(.blue)
                        }
                    }
                }

                Button(action: {
                    
                    EnvironmentConfig.shared.currentType = .prod
                    dismiss()
                }) {
                    HStack {
                        Text("正式环境")
                        Spacer()
                        if EnvironmentConfig.shared.currentType == .prod {
                            Image(systemName: "checkmark")
                                .foregroundColor(.blue)
                        }
                    }
                }
            }
            .navigationTitle("选择环境")
        }
    }
}

